<?php
// +----------------------------------------------------------------------
// | wttai [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.wttai.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 老司机 <wutongtai@wttai.com> <http://www.wttai.com>
// +----------------------------------------------------------------------
namespace Home\Controller;

/**
 * 文档模型控制器
 * 文档模型列表和详情
 */
class TagsController extends HomeController
{

   
    public function index($p = 1)
    {
         $tagsPageNum=C(PAGE_TAGS_NUM);//每页显示的标签的数量
         $tagsM= D('Common/Tags');
         //获取当前站点下面的所有文章
         $dcIds=getSetArticle(SITE_ID);
         $tag=$tagsM->getAllTags($dcIds,$p,$tagsPageNum);
         $tag=getNameCount($tag, 'Tags', 'name');
         //dump(array_column($tag, 'tag_name'));exit;
        //  dump($tag);exit;
         $Tags_count = $tagsM->getAllTagsCount($dcIds);
         $Tags_count=array_filter(array_column($Tags_count, 'tag_name'));
         $Tags_count=count($Tags_count);
         $page = ceil($Tags_count/$tagsPageNum)+1;
        
         if ($p >= $page){
             redirect('/');
         }
         if ($Tags_count > 0) {
             //$list = D('Document')->alias('a')->field('a.*')->page($p, $list_row)->join('__ARTICLE_CATEGORY__ AS `b` on a.`id` = b.`article_id`')->where($map)->select();
             $this->_page($Tags_count, $tagsPageNum, '/tags'.'-'.urlencode('[PAGE]').'.html');
         }
         $this->header();//头部内容
         $this->assign('tag',$tag);
         $this->assign('page',$page);//分页s
         $this->assign('p',$p);//当前页
         $this->display('tags');
    }
        

}
